package com.atguigu.classroom.vod.controller;


import com.atguigu.classroom.model.vod.Teacher;
import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.vo.vod.TeacherQueryVo;
import com.atguigu.classroom.vod.service.TeacherService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "讲师管理接口")
@RestController
@RequestMapping(value="/admin/vod/teacher/")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @ApiOperation(value = "查询所有讲师")
    @GetMapping("findAll")
    public Result findAllTeacher(){
        return Result.ok(teacherService.findAll());
    }
    @ApiOperation("逻辑删除讲师")
    @DeleteMapping("remove/{id}")
    public Result removeTeacher(@PathVariable Long id){
        boolean b = teacherService.removeBtId(id);
        if(b){
            return Result.ok(null);
        }else {
            return Result.fail();
        }
    }
    @ApiOperation("分页查询讲师")
    @PostMapping("findQueryPage/{current}/{limit}")
    public Result findPage(@PathVariable("current") int current,
                           @PathVariable("limit") int limit,
                           @RequestBody(required = false) TeacherQueryVo teacherQueryVo){
        Page<Teacher> teacherPage=teacherService.findQueryPage(current,limit,teacherQueryVo);
        return Result.ok(teacherPage);
    }
    @ApiOperation("添加讲师")
    @PostMapping("saveTeacher")
    public Result saveTeacher(@RequestBody Teacher teacher){
        boolean t=teacherService.saveTeacher(teacher);
        if (t){
            return Result.ok(null);
        }
        return Result.fail();
    }
    @ApiOperation("根据id查询讲师")
    @GetMapping("getTeacher/{id}")
    public Result getTeacher(@PathVariable Long id){
        return Result.ok(teacherService.getById(id));
    }
    @ApiOperation("修改讲师信息")
    @PostMapping("updateTeacher")
    public Result updateTeacher(@RequestBody Teacher teacher){
        boolean t=teacherService.updateTeacher(teacher);
        if (t){
            return Result.ok(null);
        }
        return Result.fail();
    }
    @ApiOperation("批量删除讲师")
    @DeleteMapping("removeBatch")
    public Result removeBatch(@RequestBody List<Long> ids){
        teacherService.delBatch(ids);
        return Result.ok(null);
    }
}

